package com.success.application.base;

import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.ViewStub;

import com.success.application.myapplication.R;
import com.success.application.widget.TitleBar;

import butterknife.Bind;

/**
 * Created by ChrisWong on 2017/1/18.
 */

public abstract class BaseTitleFragment extends BaseFragment {

    @Bind(R.id.nav_title_bar)
    TitleBar mTitleBar;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_base_title;
    }

    @LayoutRes
    protected abstract int getContentLayoutId();

    @Override
    protected void onBindViewBefore(View root) {
        super.onBindViewBefore(root);
        // on before onBindViewBefore call
        ViewStub stub = (ViewStub) root.findViewById(R.id.lay_content);
        stub.setLayoutResource(getContentLayoutId());
        stub.inflate();
    }

    protected void initBundle(Bundle bundle){
        super.initBundle(bundle);
    }

    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
        mTitleBar = (TitleBar) root.findViewById(R.id.nav_title_bar);
        mTitleBar.setTitle(getTitleRes());
        mTitleBar.setLeftIcon(getLeftIconRes());
        mTitleBar.setRightIcon(getRightIconRes());
        mTitleBar.setLeftIconOnClickListener(getLeftIconClickListener());
        mTitleBar.setRightIconOnClickListener(getRightIconClickListener());
    }

    protected void initData() {
        super.initData();
    }

    @StringRes
    protected abstract int getTitleRes();

    @DrawableRes
    protected int getLeftIconRes() {
        return 0;
    }

    @DrawableRes
    protected int getRightIconRes() {
        return 0;
    }

    protected View.OnClickListener getLeftIconClickListener() {
        return null;
    }

    protected View.OnClickListener getRightIconClickListener() {
        return null;
    }
}
